import { loginAPI, sendCodeAPI } from '@/api/login';
import { setAuth } from '@/utils/storage';
import { AppDispatch } from '..';

export const sendCodeAction = (mobile: string) => {
  return async () => {
    await sendCodeAPI(mobile);
  };
};

export const loginAction = (mobile: string, code: string) => {
  return async (dispatch: AppDispatch) => {
    const res = await loginAPI(mobile, code);
    setAuth(res.data);

    dispatch({ type: 'user/saveAuth', payload: res.data });
  };
};
